package main

import (
	"excel/types"
	"excel/utils"
	"fmt"
	"os"
	"path/filepath"
)

var (
	sheet      = "教职工"
	newPath, _ = filepath.Abs("./new")
)

func main() {
	paths, _ := filepath.Abs("./excel")

	err := filepath.Walk(paths, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if !info.IsDir() {
			if filepath.Ext(path) == ".xlsx" {
				var data []types.ExcelDemo
				if err := utils.ReadExcel(path, sheet, &data); err != nil {
					fmt.Println(err)
				}
				os.MkdirAll(newPath, 0755)
				file := filepath.Join(newPath, filepath.Base(path))
				if _, err := os.Stat(file); err == nil {
					utils.WriteExcel(data, "新教职工信息", file)
				} else {
					if os.IsNotExist(err) {
						utils.WriteNewExcel(data, "教职工信息", file)
					} else {
						fmt.Println("err", err)
					}
				}
			}
		}
		return nil
	})

	if err != nil {
		fmt.Println("")
	}
}
